{extend name='admin@public/content'}

{block name="button"}
<!--{if auth("$classuri/add")}-->
<button data-modal='{:url("$classuri/add")}' data-title="新增项目" class='layui-btn layui-btn-sm layui-btn-primary'>新增项目</button>
<!--{/if}-->
{if auth("$classuri/add")}
<button data-modal='{:url("$classuri/import")}' data-title="批量导入" class='layui-btn layui-btn-sm layui-btn-primary'>批量导入</button>
{/if}
<button data-href='/demo_item.xlsx' data-title="下载模板" class='layui-btn layui-btn-sm layui-btn-primary'>下载模板</button>
{/block}

{block name="content"}
<!-- 表单搜索 开始 -->
<form class="layui-form layui-form-pane form-search" action="{:request()->url()}" onsubmit="return false" method="get">

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">体检项目</label>
        <div class="layui-input-inline">
            <input name="name" value="{$Think.get.name}" placeholder="请输入体检项目" class="layui-input">
        </div>
    </div>

    <!--{if !empty($mec_list)}-->
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">体检机构</label>
        <div class="layui-input-inline">
            <select name="mec_id" lay-search lay-filter="s_mec_id" id="s_mec_id">
                <option value="">所有</option>
                {foreach $mec_list as $key=>$value}
                <!--{if $Think.get.mec_id eq $key}-->
                <option selected="selected" value="{$key}">{$value}</option>
                <!--{else}-->
                <option value="{$key}">{$value}</option>
                <!--{/if}-->
                {/foreach}
            </select>
        </div>
    </div>
    <!--{/if}-->

    <!--{if !empty($mec_list)}-->
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">项目分类</label>
        <div class="layui-input-inline">
            <select name="item_set_id" lay-search id="s_item_set_id">

            </select>
        </div>
    </div>
    <!--{/if}-->

    <div class="layui-form-item layui-inline">
        <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
    </div>

</form>
<!-- 表单搜索 结束 -->

<form onsubmit="return false;" data-auto="true" method="post">
    <!--{if empty($list)}-->
    <p class="help-block text-center well">没 有 记 录 哦！</p>
    <!--{else}-->
    <input type="hidden" value="resort" name="action">
    <table class="layui-table notevent" lay-skin="line">
        <thead>
        <tr>
            <th class='list-table-check-td'>
                <input data-none-auto="" data-check-target='.list-check-box' type='checkbox'/>
            </th>
            <th class='list-table-sort-td w60'>ID</th>
            <th class='list-table-sort-td'>
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-xs">排 序</button>
            </th>
            <th class="w300">体检机构</th>
            <th class="w200">项目分类</th>
            <th>体检项目</th>
            <th class="w120">单项价格</th>
            <th class='text-center w200'>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $key=>$vo}
        <tr>
            <td class='list-table-check-td'>
                <input class="list-check-box" value='{$vo.id}' type='checkbox'/>
            </td>
            <td class='list-table-sort-td'>{$vo.id}</td>
            <td class='list-table-sort-td'>
                <input name="_{$vo.id}" value="{$vo.sort}" class="list-sort-input"/>
            </td>
            <td>{$vo.mec}</td>
            <td>{$vo.item_set}</td>
            <td>{$vo.name}</td>
            <td>{$vo.price}</td>
            <td class='text-center nowrap'>
                {if auth("$classuri/edit")}
                <a data-modal='{:url("$classuri/edit")}?id={$vo.id}' href="javascript:void(0)">编辑</a>
                {/if}
                {if auth("$classuri/remove")}
                <span class="text-explode">|</span>
                <a data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/remove")}' href="javascript:void(0)">删除</a>
                {/if}
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    {if isset($page)}<p>{$page|raw}</p>{/if}
    <!--{/if}-->
</form>
<script>
    var itemSetListS = JSON.parse('{$item_set_list|raw}');
    var selectIndexM = {$Think.get.mec_id|default="0"};

    function renderForm() {
        layui.use('form', function(){
            var form = layui.form;
            form.render();
        });
    }

    // 初始化
    function initSelectS() {
        if (selectIndexM > 0) {
            $("#s_mec_id").val(selectIndexM);
        }

        var id = $("#s_mec_id").val();
        onMecChange(id);

        renderForm();
    }

    function onMecChange(id) {
        $("#s_item_set_id").empty();
        $("#s_item_set_id").append(new Option("所有", 0, false, true));

        $.each(itemSetListS[id], function(idx, obj) {
            var selected = false;
            $("#s_item_set_id").append(new Option(obj.name, obj.id, false, selected));
        });

        renderForm();
    }

    (function () {
        layui.use('form', function(){
            var form = layui.form;
            form.render();

            form.on('select(s_mec_id)', function(data) {
                var id = data.value;
                onMecChange(id);

            });
        });

        initSelectS();
    })();
</script>
{/block}